<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }

    .cls {
      width: 300px;
      height: 300px;
    }

    .dv {
      background-color: hotpink;
      border: 10px solid black;
    }

    .blue {
      color: red;
    }
  </style>
</head>

<body>
  <div class="cls">
    Lorem ipsum, dolor sit amet
  </div>
</body>
<script>
  /* 
    添加多个类名
      ele.classList.add("aaa","bbb","ccc");
    移除一个类名
      ele.classList.remove("aaa");
    移除多个类
      ele.classList.remove("aaa","bbb","ccc");
    切换类名
      ele.classList.toggle("newAaa");
    获取第一个类名
      ele.classList[0]
    获取到第几个类名
      ele.classList.item(n)
    查看是否存在该类名
      ele.classList.contains("aaa")
  */
  let cls = document.querySelector(".cls");
  cls.addEventListener("click", (e) => {
    // let i = e.currentTarget.classList[0];
    // e.currentTarget.classList.add("blue", "dv");
    e.currentTarget.classList.toggle("dv");
    let i = e.currentTarget.classList.item(1);
    console.log(i);
  });
</script>

</html>